<?php
    namespace Admin\Controller;

    use Org\Util\ArrayList;
    use Org\Util\Date;
    use Think\Controller;

    class ClassifyController extends BasesController
    {
        public function index()
        {
            $pagesize = 5;#每页数量
            $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
            $count = count(M('classify')->select());
            $offset = $pagesize * ($p - 1);//计算记录偏移量
            $classify = M('classify')
                ->limit($offset . ',' . $pagesize)
                ->select();
            $page = new \Think\Page($count, $pagesize);
            $page = $page->show();
            $this->assign('page', $page);
            $this->assign('classify',$classify);
            $this->display('showClassify');
        }

        public function addClassify(){
            $this->display();

        }
        public function updateInfo(){
            $classify_id = I('classify_id');
            $this->assign('classify',M('classify')->find($classify_id));
            $this->display('addClassify');
        }
        public function update(){
            $classify_name = I('classify_name');
            $classify_id = I('classify_id');
            $data['classify_name'] = $classify_name;
            $classify = M('classify');
            if ($classify_id==null){
                if ($classify->add($data)) {
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                if ($classify->where('classify_id='.$classify_id)->save($data)) {
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败',U('Classify/index'));
                }
            }
        }

        public function delete(){
            $classify_id = I('classify_id');
            $classify = M('classify');
            if ($classify->delete($classify_id)) {
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }



    }